/*
 * @LastEditTime: 2023-02-28 14:36:34
 */
import { router } from "../index";
import { Comment } from "../../Models/Comment.schema";
import { CommentController } from "../../Controller/Comment.controller";
import { createCommentDTO, updateCommentDTO } from "../../DTO/Comment.dto";

const commentModel = new CommentController(Comment);

//获取评论
router.get("/comment", async (ctx, next) => {
  if (ctx.request.query.username)
    ctx.body = await commentModel.findByUsername(ctx.request.query.username.toString())
  else if (ctx.request.query.musicId)
    ctx.body = await commentModel.findById(ctx.request.query.musicId.toString())
});


// 创建评论
router.post("/comment", async (ctx, next) => {
  console.log(ctx.request.body);
  ctx.body = await commentModel.createItem(ctx.request.body as createCommentDTO);
});

// 更新评论
router.patch("/comment/:id", async (ctx, next) => {
  if (ctx.params.id)
    ctx.body = await commentModel.updateById(ctx.params.id, ctx.request.body as updateCommentDTO);
});